package com.aote.work;

 

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.browsesoft.PropertiesService;


/**
 * 工作任务管理类
 *
 */
public class WorkFactory {


	private static WorkFactory self = null;
	
	
	//保存工作链表
	private Map<String,Work> works = new HashMap<String,Work>();
	
	
	private WorkFactory()
	{
	  this.load();
	}
	
	
	public static WorkFactory getInstance()
	{
	    if(self == null)
	    {
	      self = new WorkFactory();
	    }
	    return self;
	}
	
	/**
	 * 加载任务sql
	 */
	private void load()
	{
	   Element worksElem = (Element) PropertiesService.getDocument().getElementsByTagName("works").item(0);
	   NodeList workList = worksElem.getElementsByTagName("work");
	   for(int i = 0 ; i < workList.getLength();i++)
	   {
		   Element workElem = (Element) workList.item(i);
		   String name = workElem.getAttribute("name");
		   Work w = new Work(name, workElem);
		   this.works.put(name,w);
	   }
	}
	
	
	/**
	 * 某项工作任务数量
	 */
	public Map amount(String name)
	{
	    Work w = this.works.get(name);
	    return w.amount();
	}
	
	
	/**
	 * 得到工作
	 */
	public Map getWork(String name,int num)
	{
		Work w = this.works.get(name);
		return w.getWork(num);
	}
	
}
